#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""This plugin will output the kanji of the current card to a file"""
# Change this to the kanji field's name
KANJI_FIELD = "Kanji"

from ankiqt import mw
from ankiqt import ui
import codecs
import os

def print_kanji(self, nosound=False, draw_question=ui.view.View.drawQuestion):
    # Draw the question
    draw_question(self, nosound)
    try:
        # Make a kueri folder first, just in case
        os.mkdir(os.path.expanduser('~/.kueri'))
    except OSError: # If it already exists, just ignore the error
        pass
    # Write the kanji to a file
    file = codecs.open(os.path.expanduser('~/.kueri/anki'), encoding='utf-8', mode='w')
    # Get it from the right field
    file.write(mw.currentCard.fact[KANJI_FIELD])
    file.close()    
    
ui.view.View.drawQuestion = print_kanji
mw.registerPlugin("Send to Kueri", 0)
 